import { createSlice } from '@reduxjs/toolkit'
const userStore = createSlice({
	name: 'user',
	initialState: {
		isOpen: false,
		userInfo: {
			token: localStorage.getItem('token') || "",
			username: localStorage.getItem('username') || "",
		},
	},
	reducers: {
		setIsOpen(state, action) {
			state.isOpen = action.payload
		},
		setUserInfo(state, action) {
			console.log("退出登录", action.payload)
			state.userInfo = action.payload
			localStorage.setItem('username', action.payload?.username)
			localStorage.setItem('token', action.payload?.token)
		},
	},
})
export const { setIsOpen, setUserInfo } = userStore.actions
export default userStore.reducer
